# create table dump script for tables:
<#list doc.all.object.@name?sort as modelname>
# ${modelname}
</#list>
<#list doc.all.object as object>

create table `${object.@name}` (
    id bigint unsigned not null auto_increment,
<#list object.formScope?children as att>
    <#if att?node_name != "object" && att?node_type == "element">
        ${att.@fieldName} <#t>
        <#if att?node_name == "boolean">
        tinyint(1) <#t>
            <#if att.@default[0]??>
            default <#if att.@default == "true">1<#else>0</#if> <#t>
            </#if>
        <#elseif att?node_name == "date">
        date <#t>
        <#elseif att?node_name == "datetime">
        datetime <#t>
        <#elseif att?node_name == "enum">
        enum(<#t>
            <#list att.element as value>
        '${value.@name}'<#if value_has_next>,</#if><#t>
            </#list>
        ) <#t>
            <#if att.@default[0]??>
        default '${att.@default}' <#t>
            </#if>
        <#elseif att?node_name=="integer">
        int <#t>
            <#if att.@default[0]??>
        default ${att.@default} <#t>
            </#if>
        <#elseif att?node_name=="long">
        bigint <#t>
            <#if att.@parentClass[0]??>
        unsigned <#t>
            </#if>
            <#if att.@default[0]??>
            default ${att.@default} <#t>
            </#if>
        <#elseif att?node_name=="double">
        double <#t>
            <#if att.@default[0]??>
            default ${att.@default} <#t>
            </#if>
        <#elseif att?node_name=="string">
            <#if att.@maxlength?number &gt; 16000000>
        longtext <#t>
            <#elseif att.@maxlength?number &gt; 65000>
        mediumtext <#t>
            <#elseif att.@maxlength?number &gt; 255>
        text <#t>
            <#else>
        varchar(${att.@maxlength}) <#t>
                <#if att.@default[0]??>
        default '${att.@default}' <#t>
                </#if>
            </#if>
        <#elseif att?node_name == "html">
        longtext <#t>
        </#if>
        <#if att.@notnull[0]?? && att.@notnull == "true">
        not null <#t>
        </#if>,
    </#if>
</#list>
<#if object.trashcan == "true">
        roDeleted boolean not null default false,
</#if>
        creationDate timestamp default CURRENT_TIMESTAMP, updateDate timestamp null
        , primary key (id)
<#list doc["//attributes/*/finder[not(ancestor::set)]"] as finder>
    <#if finder?parent?parent?parent.@name == object.@name>
        <#if finder?parent?node_name == "object">
        , foreign key ${object.@name}_${finder?parent.@fieldName}Id (${finder?parent.@fieldName}Id) references ${finder?parent.@class}(id)<#if finder?parent.@cascade == 'true'> on delete cascade</#if>
        <#else>
        , index ${object.@name}_${finder?parent.@fieldName} (${finder?parent.@fieldName})
        </#if>
    </#if>
</#list>
        ) default CHARSET=utf8 ENGINE INNODB;


</#list>